package com.cn.lf.wx.dacs.bussiness.author.bean;

import com.cn.lf.wx.dacs.bussiness.author.utils.Code;

/**
 * 统一返回体
 */
public class ReturnEntity {

	// 是否成功
	private boolean success;
	// 状态码
	private int code;
	// 描述
	private String message;
	// 数据
	private Object data;
	// 时间戳
	private long timestamp;
	
	

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public Object getData() {
		return data;
	}

	public ReturnEntity() {
		this.timestamp = System.currentTimeMillis();
	}

	// 提供一些静态的方法，可以快速地创建返回对象
	public static ReturnEntity SUCCESS() {
		ReturnEntity r = new ReturnEntity();
		r.code = Code.SUCCESS;
		r.message = Code.Msg.SUCCESS;
		r.success = true;
		return r;
	}

	public static ReturnEntity SUCCESS(String message) {
		ReturnEntity r = SUCCESS();
		r.message = message;
		r.success = true;
		return r;
	}

	public static ReturnEntity SUCCESS(int code, String message) {
		ReturnEntity r = SUCCESS(message);
		r.setCode(code);
		return r;
	}

	public static ReturnEntity FAILED() {
		ReturnEntity r = new ReturnEntity();
		r.code = Code.FILED;
		r.message = Code.Msg.FILED;
		r.success = false;
		return r;
	}

	public static ReturnEntity FAILED(String message) {
		ReturnEntity r = FAILED();
		r.message = message;
		r.success = false;
		return r;
	}

	public static ReturnEntity FAILED(int code, String message) {
		ReturnEntity r = FAILED(message);
		r.setCode(code);
		return r;
	}

	public static ReturnEntity NOT_LOGIN() {
		return FAILED(Code.NOT_LOGIN, Code.Msg.NOT_LOGIN);
	}

	public ReturnEntity setData(Object data) {
		this.data = data;
		return this;
	}
}
